package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.TSCServiceType;
import com.shrcl.engineerprocess.domain.TSCServiceTypeCategory;
import com.shrcl.engineerprocess.domain.TSCServiceTypeDAO;
import com.shrcl.engineerprocess.domain.TSCServiceTypeOptionItem;
import com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseDAOService;
import edu.fudan.mylang.pf.IGenericQuery;
import java.util.Collection;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrcl.engineerprocess.domain.TSCServiceTypeDAO")
public class TSCServiceTypeDAOImpl extends BaseDAOService<TSCServiceType> implements TSCServiceTypeDAO {
  public TSCServiceType create(final Procedure1<? super TSCServiceType> init) {TSCServiceType tSCServiceType=TSCServiceTypeImpl.create(getObjectFactory());
    final Procedure1<TSCServiceType> _function = new Procedure1<TSCServiceType>() {
        public void apply(final TSCServiceType it) {
          init.apply(it);
          String _name = it.getName();
          Boolean _isExisting = TSCServiceTypeDAOImpl.this.isExisting(_name);
          boolean _equals = ((_isExisting).booleanValue() == false);
          Validates.Assert(_equals, "\u670D\u52A1\u540D\u79F0\u5DF2\u5B58\u5728");
        }
      };
    TSCServiceType _doubleArrow = ObjectExtensions.<TSCServiceType>operator_doubleArrow(tSCServiceType, _function);
    return _doubleArrow;
  }
  
  public Collection<TSCServiceType> getAllTSCServiceType() {IGenericQuery<TSCServiceType> query=getObjectFactory().createGenericQuery(TSCServiceType.class,"select e from com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl as e   where  e.active = 1      ");
    Collection<TSCServiceType> _list = query.list();
    return _list;
  }
  
  public void delete(final TSCServiceType serviceType) {getObjectFactory().delete(serviceType);
    
  }
  
  public void obsolete(final TSCServiceType serviceType) {
    serviceType.setIsActive(Boolean.valueOf(false));
  }
  
  public void recover(final TSCServiceType serviceType) {
    serviceType.setIsActive(Boolean.valueOf(true));
  }
  
  public Collection<TSCServiceTypeOptionItem> findByCategoryAndTypeName(final TSCServiceTypeCategory category, final String name) {
    IGenericQuery<TSCServiceType> query=getObjectFactory().createGenericQuery(TSCServiceType.class,"select e from com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl as e   where (((e.category) = (:category)) and ((e.name) = (:name))) and  e.active = 1      ").setParameter("category",category).setParameter("name",name);
    TSCServiceType _uniqueResult = query.uniqueResult();
    Collection<TSCServiceTypeOptionItem> _optionItems = _uniqueResult==null?(Collection<TSCServiceTypeOptionItem>)null:_uniqueResult.getOptionItems();
    return _optionItems;
  }
  
  public Boolean isExisting(final String name) {
    IGenericQuery<TSCServiceType> query=getObjectFactory().createGenericQuery(TSCServiceType.class,"select e from com.shrcl.engineerprocess.domain.impl.TSCServiceTypeImpl as e   where ((e.name) = (:name)) and  e.active = 1      ").setParameter("name",name);
    Collection<TSCServiceType> _list = query.list();
    int _size = _list.size();
    boolean _greaterEqualsThan = (_size >= 2);
    return Boolean.valueOf(_greaterEqualsThan);
  }
}
